define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    "index_url": "basic/homework/index",
                    "add_url": "basic/homework/add",
                    "edit_url": "basic/homework/edit",
                    "del_url": "basic/homework/del",
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'state', checkbox: true,},
                        {field: 'students.username', title: '学生名称'},
                        {field: 'original_image', title: '作业图片', events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'create_time', title: '提交时间', formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'status', title: '批改状态', formatter: Table.api.formatter.status, searchList: { 0: __('未批改'), 1: __('AI批改'), 2: __('人工批改'), 3: __('已生成ai批改图片') }},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
            });

            // 为表格绑定事件
            Table.api.bindevent(table);            
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
